import logging
import logging.handlers
import os

log_base_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'log')


def create_logger(logger_name, log_file_name):
    if not os.path.exists(log_base_path):
        os.makedirs(log_base_path)
    log_path = os.path.join(log_base_path, log_file_name)
    logger = logging.getLogger(logger_name)
    formatter = logging.Formatter(
        "%(name)-12s %(asctime)s %(levelname)-8s "
        "%(filename)s (%(lineno)d)\t####\t"
        "%(message)s", "%a, %d %b %Y %H:%M:%S", )
    file_handler = logging.handlers.TimedRotatingFileHandler(log_path, "midnight", 1)
    file_handler.suffix = "%Y%m%d"
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)
    logger.setLevel(logging.INFO)
    return logger
